<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" id="year">
    <input type="text" id="month">
    <input type="text" id="day">
    <input type="button" value="计算" id="btn">
    <input type="text" id="res">

    <script>

        // 思路：
        //   计算是当年的第几天


        // 1 拿对象
        var oYear = document.getElementById('year') ;
        var oMonth = document.getElementById('month') ;
        var oDay = document.getElementById('day') ;
        var oBtn = document.getElementById('btn') ;
        var oRes = document.getElementById('res') ;

        // 2 事件
        oBtn.onclick = function () {  
            // 拿到年年月日
            var y = oYear.value * 1 ;
            var m = oMonth.value * 1 ;
            var d = oDay.value * 1 ;


            // 最终求和的结果   求和 -> 初始值为0
            var sum = 0 ;


            // 二月的总天数  --- 根据闰年来计算的
            var erDay ;
            if(y % 4 === 0 && y % 100 !== 0 || y % 400 === 0) {
                erDay = 29
            } else {
                erDay = 28 ;
            }

            // 根据月份进行计算
            if(m === 1) {
                sum += d ;
            }
            // 2000 2 3
            else if (m === 2) {
                sum += 31 + d ;
            }
            // 2000 3 3
            else if (m === 3) {
                sum += 31 + erDay + d ;
            }
            else if (m === 4) {
                sum += 31 + erDay + 31 + d ;
            }
            else if (m === 5) {
                sum += 31 + erDay + 31 + 30 + d ;
            }
            else if (m === 6) {
                sum += 31 + erDay + 31 + 30 + 31 + d ;
            }
            else if (m === 7) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + d ;
            }
            else if (m === 8) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + 31 + d ;
            }
            else if (m === 9) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + 31 + 31 + d ;
            }
            else if (m === 10) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d ;
            }
            else if (m === 11) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d ;
            }
            else if (m === 12) {
                sum += 31 + erDay + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d ;
            }

            oRes.value = sum ;
            
        }


    </script>
    
</body>
</html>